<template>
  <div class="my-counter">
    <!-- 点击 + 或者 - 时调用对应父组件的函数 -->
    <button type="button" class="btn btn-light" @click="$emit('les')">-</button>
    <input
      type="number"
      class="form-control inp"
      :value="value"
      @input="inputFn"
    />
    <button type="button" class="btn btn-light" @click="$emit('add')">+</button>
  </div>
</template>

<script>
export default {
  // 接收数量
  props: ['value'],
  methods: {
    inputFn(e) {
      this.$emit('input', e.target.value)
    },
  },
}
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>
